﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class MonHocService : IMonHoc
    {
        public ICollection<MonHoc> GetAllMonHoc()
        {
            var data = new DataClasses1DataContext();
            return data.MonHocs.ToList();
        }


        public Boolean InsertMonHoc(MonHoc info)
        {
            var data = new DataClasses1DataContext();
            try
            {
                MonHoc newinfo = new MonHoc();
                newinfo.tenmh = info.tenmh;
                newinfo.sotc = info.sotc;
                data.MonHocs.InsertOnSubmit(newinfo);
                data.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {

                return false;
            }
        }
        public Boolean DeleteMonHoc(String id)
        {
            var data = new DataClasses1DataContext();
            try
            {
                var re = (from mh in data.MonHocs where mh.mamh == int.Parse(id) select mh).Single();
                if (re == null) return false;
                data.MonHocs.DeleteOnSubmit(re);
                data.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public Boolean UpdateMonHoc(MonHoc info)
        {
            var data = new DataClasses1DataContext();
            try
            {
                var re = (from mh in data.MonHocs where mh.mamh == info.mamh select mh).Single();
                if (re == null) return false;
                re.tenmh = info.tenmh;
                re.sotc = info.sotc;
                data.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }
    }
}
